package leetcode.dp;


import java.util.ArrayList;
import java.util.Collections;

// 674. 最长连续递增序列
public class FindLengthOfLCIS {
    public static void main(String[] args) {
        int[] data = {1, 3, 5, 4, 7};
        System.out.println(findLengthOfLCIS2(data));
    }

    // 类似双指针
    public static int findLengthOfLCIS(int[] nums) {
        int n = nums.length;
        int res = 1;
        int index = 0;
        for (int i = 1; i < n; i++) {
            if (nums[i] > nums[i - 1]) {
                res = Math.max(i - index + 1, res);
            } else {
                index = i;
            }
        }
        return res;
    }

    public static int findLengthOfLCIS2(int[] nums) {
        int res = 1;
        int count = 1;
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i + 1] > nums[i]) {
                count++;
            } else {
                count = 1;
            }
//            if (count>res){
//                res = count;
//            }
            // 利用一个新变量将结果返回出去，要不count的值会被改为1
            res = Math.max(count, res);
        }

        return res;
    }
}
